package com.boot.security.server.dao.mffl;

import java.util.List;
import java.util.Map;

import com.boot.security.server.model.mffl.Vo.MfflInformationReplyVo;
import org.apache.ibatis.annotations.*;

import com.boot.security.server.model.mffl.MfflInformationReply;

@Mapper
public interface MfflInformationReplyDao {

    @Select("select * from mffl_information_reply t where t.id = #{id}")
    MfflInformationReply getById(Long id);

    @Delete("delete from mffl_information_reply where id = #{id}")
    int delete(Long id);

    int update(MfflInformationReply mfflInformationReply);

    @Options(useGeneratedKeys = true, keyProperty = "id")
    @Insert("insert into mffl_information_reply(information_id, title, user_id, content, image_url, type, topid, createTime, updateTime, deleteTime) values(#{informationId}, #{title}, #{userId}, #{content}, #{imageUrl}, #{type}, #{topid},now(), now(),  now())")
    int save(MfflInformationReply mfflInformationReply);

    int count(@Param("params") Map<String, Object> params);

    List<MfflInformationReplyVo> list(@Param("params") Map<String, Object> params, @Param("offset") Integer offset, @Param("limit") Integer limit);

    int commentCount(@Param("params") Map<String, Object> params);

    List<MfflInformationReplyVo> commentList(@Param("params") Map<String, Object> params, @Param("offset") Integer offset, @Param("limit") Integer limit);

    //资讯-查询回答评论集合
    List<MfflInformationReplyVo> getMfflInformationReplyListByInformationId(@Param("informationId") long id,@Param("userId") long userId);

    //资讯-查询回答
    MfflInformationReplyVo getMfflInformationReplyVoById(@Param("replyId") long replyId,@Param("userId") long userId);

    //资讯-回答详请
    List<MfflInformationReplyVo> getMfflInformationReplyListById(@Param("replyId") long replyId);

    //资讯-回答-添加和取消赞
    @Update("update mffl_information_reply set praise=#{praise} where id=#{replyId}")
    void updateAddPraise(@Param("praise") int i, @Param("replyId") long replyId);
    //资讯-回答-添加和取消踩
    @Update("update mffl_information_reply set tread=#{tread} where id=#{replyId}")
    void updateAddTrade(@Param("tread") int i, @Param("replyId") long replyId);

    //资讯-我的话题-删除绑定话题的回答
    @Update("update mffl_information_reply set delete_state = 0 where information_id = #{informationId} ")
    void delReplyByInformation(@Param("informationId") long informationId);

    //资讯-我的回答
    List<MfflInformationReplyVo> getReplyListByUserId(@Param("userId") Long userId);

    //资讯-我的回答-删除回答
    @Update("update mffl_information_reply set delete_state = 0 where id = #{replyId} ")
    int delMyReply(@Param("replyId") long replyId);

    @Update("update mffl_information_reply set delete_state = 0 where topid = #{replyId} ")
    void delMyReplyOfReply(@Param("replyId") long replyId);

    //资讯-我的评论
    List<MfflInformationReplyVo> getCommentListByUserId(@Param("userId") Long userId);

    @Update("update mffl_information_reply set number = number-1 where id = #{id} ")
    void updateNumber(@Param("id") Integer id);
}